package transforms;
import java.util.Iterator;

import org.objectweb.asm.tree.FieldNode;

import com.rshacking.rhf.files.ClassContainer;
import com.rshacking.rhf.updater.Transform;
import com.rshacking.rhf.updater.hooks.ClassHook;
import com.rshacking.rhf.updater.hooks.HooksList;

public class PlayerDefTransform extends Transform {

	@Override
	public boolean canActivate(final HooksList hooks, final ClassContainer cc) {
		final ClassHook an = hooks.get("PlayerDef");
		if (an == null)
			return false;
		return cc.getName().equals(an.getOrigName());
	}

	@Override
	public boolean execute(final HooksList hooks, final ClassContainer cc) {

		final Iterator<FieldNode> fields = cc.getASM().fields.iterator();
		while (fields.hasNext()) {
			final FieldNode fn = fields.next();
			if (fn.isFieldStatic()) {
                continue;
            }
			if (fn.desc.equals("Z")) {
				hooks.get("PlayerDef").add("male", fn);
			}
			if (fn.desc.startsWith("[L")) {
			    hooks.add("Particle", fn.desc);
			    hooks.get("PlayerDef").add("particles", fn);
			}
			if (fn.desc.equals("J")) {
			    hooks.get("PlayerDef").add("cField", fn);
			}
			if (fn.desc.startsWith("[I")) {
			    hooks.get("PlayerDef").add("uArray", fn);
			}
		}
		return false;
	}
}